package tesst18;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-12-01
 * Time: 8:49
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        Map<String, Goods> goodsMap;
        goodsMap = new HashMap<>();
        System.out.println("请输入三条信息: ");
        int i=0;
        while(i<3){
            System.out.println("请输入第"+(i+1)+"条商品");
            System.out.println("请输入商品编号");
            String goodsId = sc.next();
            if( goodsMap.containsKey(goodsId)){
                System.out.println("该商品编号已经存在!请重新输入!");
                continue;
            }
            System.out.println("请输入商品名称: ");
            String goodName = sc.next();
            System.out.println("请输入商品价格: ");
            double goodsPrice = 0;
            try {
                goodsPrice = sc.nextDouble();
            } catch (Exception e) {
                System.out.println("商品价格的格式不正确, 请输入数值数据!");
                sc.next();
                continue;
            }
            Goods goods= new Goods(goodsId,goodName,goodsPrice);
            goodsMap.put(goodsId, goods);
            i++;
        }
        System.out.println("商品的全部信息为: ");
        Iterator<Goods> itGoods = goodsMap.values().iterator();
        while(itGoods.hasNext()){
            System.out.println(itGoods.next());

        }

    }
}
